<?php
/**
 * 本地字符集训练测试
 */
include __DIR__.'/func/code.php';
include __DIR__.'/vendor/autoload.php';



// test_local();


function test_local()
{
	$base = __DIR__.'/font/temp/';
	$puts = __DIR__.'/font/output.txt';
	file_exists($puts) && unlink($puts);

	$handler = opendir($base);
	while( ($filename = readdir($handler)) !== false ) {
		if($filename[0] === '.') {
			continue;
		}
		$path = $base.$filename;

		// 去掉干扰线
		$img  = image_one(imagecreatefrompng($path));

		// 放大图片
		$img  = img_resize($img, 3);

		// 切割图片
		$list = img_split($img, 2000);

		$char = dirname($base);
		$text = '';
		foreach ($list as $key => $value) {
			$char_path = $char.sprintf('/char/%03d.png', $key+1);

			img_draw($value, $char_path);

			// 识别图片
			// 识别图片 code fontyp num eng
			$text .= (new TesseractOCR($char_path))->lang('fontyp')->psm(8)->run();
		}
		$text = $text.PHP_EOL;
		file_put_contents($puts, $text, FILE_APPEND);
		// exit();
	}
	echo 'test_local Done'.PHP_EOL;
}


function test_one($value='')
{
	$char_path = __DIR__.'/font/char/005.png';
	// 识别图片 code fontyp num eng
	$text = (new TesseractOCR($char_path))->lang('eng')->psm(8)->run();
	var_dump($text);
}
// test_one();



